Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

analysis: report rule state altered by other rule - v2 #12311

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jufajardini
Copy link
Contributor

Flowbits can make a rule such as a packet rule be treated as a stateful rule, without actually changing the rule type.

Add a flag to allow reporting such cases via engine analysis.

Task #7456

Link to ticket: https://redmine.openinfosecfoundation.org/issues/
https://redmine.openinfosecfoundation.org/issues/7456

Previous PR: #12286

Output samples:
flowbits:set rule

{
  "raw": "alert http any any -> any any (msg:\"Setting flowbit fb2, app_tx rule\";http.uri;content:\"something\";flowbits:set,fb2;sid:1901;)",
  "id": 1901,
  "gid": 1,
  "rev": 0,
  "msg": "Setting flowbit fb2, app_tx rule",
  "app_proto": "http_any",
  "requirements": [
    "flow"
  ],
  "type": "app_tx",
  "rule_state_dependant": false,
}

flowbits:isset rule

{
  "raw": "alert ip any any -> any any (msg:\"Is-Setting flowbit fb2, pkt rule\";flowbits:isset,fb2;sid:1904;)",
  "id": 1904,
  "gid": 1,
  "rev": 0,
  "msg": "Is-Setting flowbit fb2, pkt rule",
  "app_proto": "unknown",
  "requirements": [
    "flow"
  ],
  "type": "pkt",
  "rule_state_dependant": {
    "rule_depends_on_sid": 1901,
    "rule_depends_on_flowbit": "fb2"
  },
}

Describe changes:

  • besides indicating that there is a dependency, indicate
  • what flowbit causes it
  • what is the rule id setting said flowbit
  • I've tried to keep the init_data mostly generic, in case there are other scenarios where this could happen - but at least when it's time to report this via the engine-analysis, we need the info to fetch the variable name
  • I've removed/ discarded the idea of showing a counter of other signatures also affecting, as it's basically only the set command that does that, from what I could understand

Provide values to any of the below to override the defaults.

SV_BRANCH=OISF/suricata-verify#2201

Flowbits can make a rule such as a packet rule be treated as a stateful
rule, without actually changing the rule type.

Add a flag to allow reporting such cases via engine analysis.

Task OISF#7456
@jufajardini jufajardini changed the title analysis: report rule state altered by other rule analysis: report rule state altered by other rule - v2 Dec 20, 2024
Copy link

codecov bot commented Dec 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (master@2c0d3b8). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff            @@
##             master   #12311   +/-   ##
=========================================
  Coverage          ?   83.25%           
=========================================
  Files             ?      912           
  Lines             ?   257638           
  Branches          ?        0           
=========================================
  Hits              ?   214508           
  Misses            ?    43130           
  Partials          ?        0           
Flag Coverage Δ
fuzzcorpus 61.14% <38.46%> (?)
livemode 19.39% <7.69%> (?)
pcap 44.42% <38.46%> (?)
suricata-verify 62.87% <100.00%> (?)
unittests 59.17% <7.69%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline 24033

Copy link
Member

@inashivb inashivb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering why don't we try and combine the output of flowbits.json or make that one more rich perhaps and point to the state event to look at in there somehow w one field in the rules.json output?

Comment on lines +600 to +604

/* inter-signature state dependency */
bool is_rule_state_dependant;
uint32_t rule_state_dependant_id;
uint32_t rule_state_variable_idx;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get this info to analyzer w/o inflating this struct so much?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine. This is an init-time only helper struct

@@ -1047,6 +1047,16 @@ void EngineAnalysisRules2(const DetectEngineCtx *de_ctx, const Signature *s)
break;
}

if (s->init_data->is_rule_state_dependant) {
jb_open_object(ctx.js, "rule_state_dependant");
jb_set_uint(ctx.js, "rule_depends_on_sid", s->init_data->rule_state_dependant_id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if there are multiple dependencies?

if (s->init_data->is_rule_state_dependant) {
jb_open_object(ctx.js, "rule_state_dependant");
jb_set_uint(ctx.js, "rule_depends_on_sid", s->init_data->rule_state_dependant_id);
jb_set_string(ctx.js, "rule_depends_on_flowbit",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this just be flowbit? Seems the key is a bit redundant with the object name.

Also, as Shivani is asking: this is 1-N essentially, can we list them all? I'm changing my mind a bit on this. I think being complete is probably best.

So

"rule_state_dependant": {
    "sids": [ 1901, 124, 666 ],
    "flowbits": [ "fb2", "abc" ],
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants